﻿using Caliburn.Micro;
using MusicExplorer.Common;
using MusicExplorer.ViewModels;
using MusicExplorer.Views;
using System;
using System.Collections.Generic;
namespace MusicExplorer
{
    public sealed partial class App
    {
        private WinRTContainer m_container;

        public App()
        {
            // Preferences
            Parameters.UseSampleData = false;
            InitializeComponent();
        }

        protected override void Configure()
        {
            m_container = new WinRTContainer();
            m_container.RegisterWinRTServices();

            m_container.PerRequest<RootViewModel>()
                       .PerRequest<HomePageViewModel>()
                       .PerRequest<RepositoryPageViewModel>()
                       .PerRequest<TracksPageViewModel>()
                       .PerRequest<ErrorPageViewModel>()
                       .PerRequest<GroupEditionViewModel>();
        }

        protected override object GetInstance(System.Type service, string key)
        {
            var instance = m_container.GetInstance(service, key);
            if (instance != null)
                return instance;
            throw new Exception("Could not locate any instances.");
        }

        protected override IEnumerable<object> GetAllInstances(System.Type service)
        {
            return m_container.GetAllInstances(service);
        }

        protected override void BuildUp(object instance)
        {
            m_container.BuildUp(instance);
        }

        protected override void OnLaunched(Windows.ApplicationModel.Activation.LaunchActivatedEventArgs args)
        {
            DisplayRootViewFor<RootViewModel>();
        }

        protected async override void OnSuspending(object sender, Windows.ApplicationModel.SuspendingEventArgs e)
        {
            base.OnSuspending(sender, e);
        }

        protected override void OnResuming(object sender, object e)
        {
            base.OnResuming(sender, e);
        }
    }
}
